package com.ibeetl.admin.api.web;

import com.ibeetl.admin.api.entity.TravelPictureList;
import com.ibeetl.admin.api.service.TravelPictureService;
import com.ibeetl.admin.core.web.JsonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@Tag(
        name = "TravelPictureController")
public class TravelPictureController {
    private final Log log = LogFactory.getLog(this.getClass());
    private static final String MODEL = "/api/travel_picture_list";
    @Resource
    private TravelPictureService travelPictureService;

    @Operation(
            summary = "新增景点图片"
    )
    @PostMapping(MODEL + "/add.json")
    @CrossOrigin
    public JsonResult<TravelPictureList> add(TravelPictureList travelPictureList) {
        travelPictureList.setCreateDt(new Date());
        if(travelPictureService.save(travelPictureList)){
            Long pictureId = travelPictureService.queryNewIdByAttractionId(travelPictureList.getAttractionId(),travelPictureList.getUserId());
            travelPictureList.setPictureId(pictureId);
            return JsonResult.success(travelPictureList);
        }else{
            return JsonResult.failMessage("新增失败！");
        }

    }
    @Operation(
            summary = "更新景点视频"
    )
    @PostMapping(MODEL + "/update.json")
    @CrossOrigin
    public JsonResult<TravelPictureList> update(TravelPictureList travelPictureList) {
        travelPictureService.update(travelPictureList);
        return JsonResult.success(travelPictureList);
    }
    @Operation(
            summary = "删除景点图片"
    )
    @PostMapping(MODEL + "/deleteById.json")
    @CrossOrigin
    public JsonResult<TravelPictureList> deleteById(Long pictureId) {
        travelPictureService.delete(pictureId,3);
        return JsonResult.success();
    }

    @Operation(
            summary = "根据路线ID查询景点图片"
    )
    @PostMapping(MODEL + "/queryByAttractionId.json")
    @CrossOrigin
    public JsonResult<List> queryByAttractionId(Long attraction_id,Long user_id) {
        List<TravelPictureList>  travel_pictures  = travelPictureService.queryByAttractionId(attraction_id,user_id);
        return JsonResult.success(travel_pictures);
    }


    @Operation(
            summary = "根据景点ID查询景点图片"
    )
    @PostMapping(MODEL + "/queryByAttsId.json")
    @CrossOrigin
    public JsonResult<List> queryByAttsId(Long atts_id,Long user_id) {
        List<TravelPictureList>  travel_picture  = travelPictureService.queryByAttsId(atts_id,user_id);
        return JsonResult.success(travel_picture);
    }

    @Operation(
            summary = "根据图片ID查询景点视频"
    )
    @PostMapping(MODEL + "/queryById.json")
    @CrossOrigin
    public JsonResult<TravelPictureList> queryById(Long pictureId) {
        TravelPictureList travelPictureList = travelPictureService.queryById(pictureId);
        return JsonResult.success(travelPictureList);
    }

}
